// pages/operat/fleedTools/inStorage/scanCode/scanCode.js
const LApp=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
   StorageInfo: {},
   myDate:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var StorageInfo = {};
   if (options.code != undefined) {
    let code = [options.code];
    if (code) {
     StorageInfo.Codes = code;
     StorageInfo.Num = code.length;
     StorageInfo.ProductID = options.ProductId
    }
   } else {
   // StorageInfo.Codes = null;
    StorageInfo.Num = 0;
    StorageInfo.ProductID = 0
   }
   this.setData({
    StorageInfo: StorageInfo
   })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1];
    if (this.data.myDate==1){
      this.setData({
        StorageInfo: {}
      })
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  //click 继续扫码
  continueOper: function () {
   let that = this;
   wx.scanCode({
    success: (res) => {
     var codes = that.data.StorageInfo.Codes;
     var pId = that.data.StorageInfo.ProductID;
     if (codes){
       if (codes.indexOf(res.result) > -1) {
         wx.showToast({
           title: "该码已重复扫描",
         })
         return
       }
     }
     if (!that.data.StorageInfo.ProductID) { that.data.StorageInfo.ProductID=0}
     LApp._get({
      url: 'nbapi/fleedtool/rk/check',
      data: { code: res.result, userId: LApp.globalData.userInfo.UserID, proId: that.data.StorageInfo.ProductID },
      success: function (r) {
       if (r) {
        if (codes == null) codes = [];
        codes.push(res.result);
        var StorageInfo = {};
        StorageInfo.Codes = codes;
        StorageInfo.Num = StorageInfo.Codes.length;
        StorageInfo.ProductID =r.ProductId;
        that.setData({
         StorageInfo: StorageInfo
        })
       }
       else {
        wx.showToast({
         title: r,
        })
       }
      }
     })

    }
   })
  },
  inStorage: function () {
    let _this = this;
   // _this.data.StorageInfo.FormCode = "RK" + new Date().getTime();
        //页面传值并跳转
        if (_this.data.StorageInfo) {
          LApp.pages.add(_this);
          wx.navigateTo({
            url: '../inStorage',
          })
        }
    
    
  }
  // inStorage: function () {
  //  let _this = this;
  //  LApp._get({
  //   url: "nbapi/fleedtool/getinfo/formcode",
  //   data: { formType: 'RK', enterpriseId: LApp.globalData.userInfo.EnterpriseId },
  //   success: function (res) {
  //    _this.data.StorageInfo.FormCode = res;
  //    //页面传值并跳转
  //    if (_this.data.StorageInfo) {
  //     LApp.pages.add(_this);
  //     wx.navigateTo({
  //      url: '../inStorage',
  //     })
  //    }
  //   }
  //  })
  // }
})